package com.base.kotlin.mvp

import android.arch.lifecycle.LifecycleObserver
import android.os.Bundle
import com.base.activity.BaseActivity

/**
 * @author zhouzechao
 * Activity的mvp基类
 */
abstract class BaseMvpKActivity<T : BasePresenter<*, *>> : BaseActivity(), IView.DefaultView {

    protected var mPresenter: T? = null

    abstract fun bindViewToPresenter(): T?

    override fun onCreate(savedInstanceState: Bundle?) {
        mPresenter = bindViewToPresenter()
        mPresenter?.let {
            lifecycle.addObserver(it as LifecycleObserver)
        }
        super.onCreate(savedInstanceState)
    }

    override fun onDestroy() {
        super.onDestroy()
        mPresenter?.let { lifecycle.removeObserver(it as LifecycleObserver) }
    }

    override fun onDefaultSuccess(action: Int, data: Any?) {

    }
}